<?php
namespace app\admin\model;
class MyProject
{
    public static function create($data){
        if(!is_dir('../application/'.$data['dir'].'/config')){
            chmod('../application',0777);
            mkdir('../application/'.$data['dir'].'/config',0777,true);
        }
        $str = '<?php
/**
 * Created by PhpStorm.
 * User: 毛文科
 * Date: 2019/5/21
 * Time: 13:02
 */
return ';
            $str .='['.PHP_EOL;
            foreach ($data as $key=>$v){
                $str.= '"'.$key.'"=>"'.$v.'",'.PHP_EOL;
            }
        $str.='];'.PHP_EOL;
        $bool = file_put_contents('../application/'.$data['dir'].'/config/project.php',$str);
        return $bool;
    }
    static public function xcopy($form='/',$to='/'){
        $obj = new MyProject();
       if($data = $obj->copys($form,$to)){
           if(is_dir($form)){
               rmdir($form);
           }
        return true;
       }else{
           return false;
       }
    }
    public function copys($form,$to){
        if(!is_dir($form)){
            return true;
        }
        if(!is_dir($to)){
            mkdir($to,0777,true);
        }
        chmod($form,0777);
        chmod($to,0777);
        $array = scandir($form);
        foreach ($array as $value){
            if($value!=='.'&&$value!=='..'){
                if(is_dir($form.'/'.$value)){
                    $this->copys($form.'/'.$value,$to.'/'.$value);
                    if(is_dir($form.'/'.$value)){
                        rmdir($form.'/'.$value);
                    }
                }else{
                    if(is_file($to.'/'.$value)){
                        chmod($to.'/'.$value,0777);
                        unlink($to.'/'.$value);
                    }
                    chmod($form.'/'.$value,0777);
                    copy($form.'/'.$value,$to.'/'.$value);
                    if(is_file($form.'/'.$value)){
                        unlink($form.'/'.$value);
                    }
                }
            }
        }
        return true;
    }
}